﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace EGuayas.Web.Notificacion
{
    public partial class AlertaDetail : ucWuc
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            try{
            if (X.IsAjaxRequest)
            {
               
            }
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
        }
        protected void GridAdded(object sender, ComponentAddedEventArgs e)
        {
            try
            {
            if (X.IsAjaxRequest)
            {
                return;
            }
            var idCtl = GetIdCtlPanel();
          

            GridPanel grid = (GridPanel)e.Control;
            grid.GetStore().AutoLoadParams.Add(new Ext.Net.Parameter("query", idCtl));
            grid.Listeners.SelectionChange.Handler = "selectionChangeGridServer(item,selected,this);";
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
        }

        private string GetIdCtlPanel()
        {  
         var idCtl = "";
         try{
          
            switch(this.Parent.ID)
            {
                case "UserControlLoader1":
                    idCtl = "revizados";
                    break;
                case "UserControlLoader2":
                    idCtl = "borrados";
                    break;
                case "UserControlLoader3":
                    idCtl = "anteriores";
                    break;
            }
        }
        catch (Exception ex)
        {
            RegistrarLog(ex);
        }
            return idCtl;
        }

        protected void InfoDetailsAdded(object sender, ComponentAddedEventArgs e)
        {
            try
            {
                if (X.IsAjaxRequest)
                {
                    return;
                }
                var idCtl = GetIdCtlPanel(); 
                Ext.Net.Panel pnl = (Ext.Net.Panel)e.Control;
                Ext.Net.Toolbar tbl = (Ext.Net.Toolbar)pnl.DockedItems.First();

                if (tbl != null && idCtl != "borrados")
                {
                    Ext.Net.Button btnDelete = new Ext.Net.Button();
                    btnDelete.Text = "Borrar Notificación";
                    btnDelete.Icon = Icon.EmailDelete;
                    btnDelete.Listeners.Click.Handler="FeedViewer.FeedGrid.updateStateAlert(this.up('panel'),'B',false);";
                    tbl.Items.Add(btnDelete);
                }
                if (tbl != null && idCtl == "borrados")
                {
                    Ext.Net.Button btnDelete = new Ext.Net.Button();
                    btnDelete.Text = "Eliminar Notificación";
                    btnDelete.Icon = Icon.TextfieldDelete;
                    btnDelete.Listeners.Click.Handler = "FeedViewer.FeedGrid.updateStateAlert(this.up('panel'),'A',true);";
                    tbl.Items.Add(btnDelete);
                }
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
   
        }

    }
}